#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cstdlib>
#include <unistd.h>
#include <cerrno>
#include <string>

using namespace std;

const char* pipePath = "./myPipe";

int main()
{
    umask(0);
    int n = mkfifo(pipePath,0666);
    if(n == -1)
    {
        cout<<"error:"<<errno<<endl;//打印错误码
        exit(1);
    }
    int fd = open(pipePath,O_WRONLY);
    if(fd == -1)
    {
        perror("open");
        exit(1);
    }
    const char* message = "Hello from writer!\n";
    ssize_t t = write(fd,message,sizeof("Hello from writer!\n"));
    if(t == -1)
    {
        perror("write");
        close(fd);
        exit(1);
    }
    cout<<"message written to the pipe.\n";
    close(fd);
    return 0;
}
